#####
## Replication File:
##
## Who Supports Political Violence?
#####

################################################################################

####
## Load necessary packages
## 
## Analyses conducted in RStudio 1.0.153,
## using R 3.6 (Mac OS)
####

library(stats)
library(car)
library(lattice)
library(smacof)
library(MASS)
library(foreign)
library(party)

# Open clean dataset
vdata <- read.dta("violence data 2.dta")

################################################################################

Violence	<-	vdata$violence
Egocentric	<-	vdata$egocentric
Systemic	<-	vdata$systemic
Anxiety	<-	vdata$anxiety
Powerlessness	<-	vdata$powerless
Authoritarianism <- vdata$authoritarian
Conspiracism	<-	vdata$conthink
Corrupt	<-	vdata$corrupt
GovTrust	<-	vdata$trustgov
RaceResent	<-	vdata$raceresent
Populism	<-	vdata$populism
Insured	<-	vdata$insured
Republican	<-	vdata$rep
PIDstrength	<-	vdata$pidstrength
Conservative	<-	vdata$conserv
IDEOstrength	<-	vdata$ideostrength
Interest	<-	vdata$interest
South	<-	vdata$south
Female	<-	vdata$gender
Evangelical	<-	vdata$evangelical
Attendance	<-	vdata$attend
Military	<-	vdata$military
Income	<-	vdata$income
WhiteIdentity	<-	vdata$whiteidentity
Partisanship <- vdata$pid
Ideology <- vdata$ideo
Education <- vdata$edu

vdata2 <- as.data.frame(cbind(Violence,
                              Egocentric,
                              Systemic,
                              Anxiety,
                              Powerlessness,
                              Conspiracism,
                              Corrupt,
                              GovTrust,
                              RaceResent,
                              Populism,
                              Authoritarianism,
                              Insured,
                              Republican,
                              PIDstrength,
                              Conservative,
                              IDEOstrength,
                              Interest,
                              South,
                              Female,
                              Evangelical,
                              Attendance,
                              Military,
                              Income,
                              WhiteIdentity,
                              Partisanship,
                              Ideology, 
                              Education))

### Decision tree analysis ###

viomod <- ctree(Violence ~ Authoritarianism + Egocentric + Systemic + 
                  Anxiety + Powerlessness + Conspiracism  + Corrupt + 
                  GovTrust + RaceResent + Populism + Insured + Republican + 
                  PIDstrength + Conservative + IDEOstrength + Interest + 
                  South + Female + Evangelical + Attendance + Military + 
                  Income + WhiteIdentity + Education,
                data = vdata2)
pdf("figure4.pdf", width = 17, height = 10)
plot(viomod)
dev.off()


